Skip to content

fix: encode author names in onerror fallback to prevent XSS - #142

Merged
steipete merged 1 commit into
openclaw:mainfrom
SebTardif:fix-onerror-xss
May 16, 2026
Merged

fix: encode author names in onerror fallback to prevent XSS#142
steipete merged 1 commit into
openclaw:mainfrom
SebTardif:fix-onerror-xss

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

Problem

The onerror handlers on testimonial avatar <img> elements in index.astro and shoutouts.astro interpolate t.author directly into a JavaScript string literal:

onerror="this.src='https://ui-avatars.com/api/?name=${t.author}&...'"

Astro HTML-encodes the attribute value, but browsers decode HTML entities before executing onerror JavaScript. An author name containing a single quote (e.g. O'Malley) produces a string literal breakout that enables arbitrary script execution.

The testimonial data comes from contributor-submitted JSON files (testimonials.json, testimonials-extra.json), making this a supply-chain XSS vector.

Fix

Apply encodeURIComponent() to t.author at build time. This percent-encodes special characters, which both prevents the JS string breakout and properly URL-encodes the name parameter for the ui-avatars.com API.

Changes

  • src/pages/index.astro: 2 onerror handlers (row1 and row2 testimonial carousels)
  • src/pages/shoutouts.astro: 1 onerror handler

Verification

  • astro build passes with no errors
  • Output HTML confirmed: author names are now percent-encoded in the onerror attribute

The onerror handlers on testimonial avatar images interpolate t.author
directly into a JavaScript string literal. Because browsers decode HTML
entities before executing event handler attributes, a single quote in an
author name (e.g. O'Malley) breaks out of the JS string and enables
arbitrary script execution.

Apply encodeURIComponent() at build time so special characters are
percent-encoded, which both prevents the string breakout and properly
URL-encodes the ui-avatars.com name parameter.

Affects index.astro (2 instances) and shoutouts.astro (1 instance).

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@vercel

vercel Bot commented May 16, 2026

Copy link
Copy Markdown

@SebTardif is attempting to deploy a commit to the Jamie's projects Team on Vercel.

A member of the Team first needs to authorize it.

@steipete
steipete merged commit 49f1523 into openclaw:main May 16, 2026
19 of 21 checks passed
SebTardif added a commit to SebTardif/openclaw.ai that referenced this pull request May 24, 2026
… XSS

URL fields from JSON data files (testimonials.json, testimonials-extra.json,
community-builds.json, press.json) are rendered directly in <a href={...}>
attributes. Astro auto-escapes HTML entities but does not block dangerous
protocols like javascript:, data:, or vbscript:.

If a crafted URL like javascript:alert(document.cookie) were merged via a
community PR, it would render as a clickable XSS link on the homepage,
shoutouts, showcase, and press pages.

This adds a sanitizeUrl() utility that validates URL protocols at build time,
allowing only http:, https:, and mailto:. Dangerous protocols are replaced
with #. All existing URLs are https:// so there is no behavioral change.

Follows up on openclaw#140 and openclaw#142 which fixed related XSS vectors.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants